<?php

namespace StudyBuddy\Api\v1;

use \StudyBuddy\SubmittedQuestionWWW;
use \StudyBuddy\Utf8String;

/**
 * Object of this class represents data
 * of a question submitted via an API
 * This is not a Question object, only a submitted
 * data. The program may reject this question
 * if it does not validate for any reason and this data
 * may never become an actual question.
 *
 */
class SubmittedQuestion extends SubmittedQuestionWWW {

    public function __construct(\StudyBuddy\Registry $oRegistry) {
        $this->oRegistry = $oRegistry;
        $this->aData = $oRegistry->Request->getArray();
        d('$this->aData: ' . print_r($this->aData, 1));
        $this->oUser = $oRegistry->Viewer;
    }

    /**
     * Get name of app used for submitting
     * this question
     * @return string
     */
    public function getApp() {
        return $this->oRegistry->appName;
    }

    /**
     * Get id of app used for submitting
     * this question
     * @return null
     */
    public function getAppId() {
        return $this->oRegistry->clientAppId;
    }

    /**
     * Unlike normal WWW request, 
     * In API call we may not have 'tags' in Request,
     * so we need to fallback to default empty string here
     *
     * (non-PHPdoc)
     * @see StudyBuddy.SubmittedQuestionWWW::getUtf8Tags()
     */
    public function getUtf8Tags() {
        if (!isset($this->oTags)) {

            $tags = $this->oRegistry->Request->get('tags', 's', '');
            $this->oTags = Utf8String::factory($tags);
        }

        return $this->oTags;
    }

}
